imgPath1 = 'D:\JC2021\IVUS menkong\dataset\标签600_137\';        % 标签路径
imgPath2 = 'D:\JC2021\IVUS menkong\dataset\原图1\';        % 原图路径
imgDir1  = dir([imgPath1 '*.png']);                % 遍历所有jpg格式文件
imgDir2  = dir([imgPath2 '*.png']);
pix_sum = [];
dis_sum = [];
% for I = 1:length(imgDir1)           % 遍历结构体就可以一一处理图片了
for I = 1:length(imgDir1)
    image_name = imgDir1(I).name;   % 从数组中获取文件名
    img = imread([imgPath1, imgDir1(I).name]);  % 读取标签
    img = bwareaopen(img , 5000);               % 去掉图中的小白点
    se = strel('square',20);
    img = imdilate(img,se);                     % 补全图里小黑点
    Img = imread([imgPath2, imgDir1(I).name]);  % 读取原图
    
    img = im2bw(img);
    c = regionprops(img,'Centroid');
    centroid = cat(1,c.Centroid);  % 获取标签质心坐标
    x_label = round(centroid(1,1));  % 读取中心的x坐标，四舍五入取整，便于后面索引
    y_label = round(centroid(1,2));  % 读取中心的y坐标，四舍五入取整，便于后面索引
    % 标签对齐方式
%     dis = 256 - y_label;
%     pix = img(:,x_label);
% 
%     t = find(pix==1);
%     t = t+dis;
%     pix = zeros([512,1]);
%     pix(t) = 1;
    % 原图对齐方式
    pix = Img(y_label-190:y_label+190,x_label);  % 切换原图和标签



    
    pix_sum = [pix_sum,pix];
end
% 插值
m = imresize(pix_sum,5,'bicubic');

% 创建RL滤波器

PSF = fspecial('gaussian',7,10); 
IF1 = imfilter(m,PSF);
V = 0.002;
BlurredNoisy = imnoise(IF1,'gaussian',0,V);

% IF1 = imfilter(m, W, 'replicate');
J1 = deconvlucy(BlurredNoisy,PSF,50);




% imshow(pix_sum),hold on
figure(6)
imshow(J1),hold on
% set (gcf,'Position',[0,0,512,1024])
% axis normal；
